package com.xinwei.leetcode;

import java.util.ArrayList;
import java.util.Scanner;

public class leetcode318 {
    public static void main(String[] args) {
        //先找到两个单词长度乘积最大值
        //排除两个单词含有公共字母的
        Integer maxProduct = 0;
        Integer maxI = 0;
        Integer maxJ = 0;
        String[] words = {"abcw","baz","foo","bar","xtfn","abcdef"};
        for (int i = 0; i < words.length; i++) {
            for (int j = i + 1; j < words.length; j++) {
                if (words[i].length() * words[j].length() > maxProduct && isContainSameLetter(words[i], words[j])) {
                    maxProduct = words[i].length() * words[j].length();
                    maxI = i;
                    maxJ = j;
                }
            }
        }
        if (maxI == 0 && maxJ == 0){
            System.out.println("0");
            System.out.println("不存在这样两个单词");
        }else {
            System.out.println(maxProduct);
            System.out.println("这两个单词为\""+words[maxI]+"\",\""+words[maxJ]+"\"");
        }
    }

    //判断两个字符串中是否含有相同的字母
//    public static boolean isContainSameLetter(String a,String b){
//        char[] Achars = a.toCharArray();
//        char[] Bchars = b.toCharArray();
//        for (int i = 0; i < Achars.length; i++){
//            for (int j = 0; j < Bchars.length; j++){
//                if (Achars[i] == Bchars[j]){
//                    return false;
//                }
//            }
//        }
//        return true;
//    }

    public static boolean isContainSameLetter(String a,String b){
        for (int i = 0; i < a.length(); i++){
            for (int j = 0; j < b.length(); j++){
                if (a.charAt(i) == b.charAt(j)){
                    return false;
                }
            }
        }
        return true;
    }
}
